package cn.wp.ewallet.wmps.dao.impl;

import cn.wp.common.core.dao.JdbcSupportTemplate;
import cn.wp.common.core.dao.SqlString;
import cn.wp.ewallet.wmps.dao.ReturnYieldInfoDao;
import cn.wp.ewallet.wmps.extension.constant.EwalletWmpsConstant;
import cn.wp.ewallet.wmps.model.entity.ReturnYieldInfoDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 反息周期-数据访问层实现
 * Created by ganjie on 2020/01/12
 */
@Repository
public class ReturnYieldInfoDaoImpl implements ReturnYieldInfoDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;

    @Override
    public ReturnYieldInfoDo selectReturnYieldInfo(String prodOrderId) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select *");
        sqlString.add("from return_yield_info");
        sqlString.add("where PROD_ORDER_ID = ?");
        sqlString.add("    and RETURN_STATUS = ?");
        sqlString.add("order by RETURN_DATE asc");
        sqlString.add("limit 1");
        return jdbcSupportTemplate.selectObject(sqlString.build(), new Object[]{prodOrderId, EwalletWmpsConstant.RETURN_STATUS_WATT}, ReturnYieldInfoDo.class);
    }

    @Override
    public void update(ReturnYieldInfoDo returnYieldInfoDo) {
        jdbcSupportTemplate.updateSelective(returnYieldInfoDo);
    }

    @Override
    public void saveReturnYieldInfo(ReturnYieldInfoDo returnYieldInfoDo) {
        jdbcSupportTemplate.insert(returnYieldInfoDo);
    }

    @Override
    public List<ReturnYieldInfoDo> selectReturnYieldInfoWaitList(String prodOrderId) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select *");
        sqlString.add("from return_yield_info");
        sqlString.add("where PROD_ORDER_ID = ?");
        sqlString.add("    and RETURN_STATUS = ?");
        return jdbcSupportTemplate.selectList(sqlString.build(), new Object[]{prodOrderId, EwalletWmpsConstant.RETURN_STATUS_WATT}, ReturnYieldInfoDo.class);
    }

    @Override
    public void updateBanch(List<ReturnYieldInfoDo> returnYieldInfoDos) {
        jdbcSupportTemplate.batchUpdate(returnYieldInfoDos);
    }

    @Override
    public List<ReturnYieldInfoDo> selectReturnYieldInfoList(String prodOrderRelId) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select * from return_yield_info where PROD_ORDER_ID = ?");
        return jdbcSupportTemplate.selectList(sqlString.build(), new Object[]{prodOrderRelId}, ReturnYieldInfoDo.class);
    }
}